// 路由跳转
const jump = (type, url) => {
	switch(type){
		case 'navigateTo':
			uni.navigateTo({
				url: url,
				animationType: 'slide-in-right',
				animationDuration: 300
			});
			break;
			
		case 'navigateBack':
			uni.navigateBack({
				delta: 1,
				animationType: 'slide-out-right',
				animationDuration: 300
			});
			break;
	}
}

// 时间戳转换
const formatDate = (date) => {
	const ndate = new Date(date)
	const year = ndate.getFullYear()
	const month = ndate.getMonth().toString().padStart(2,0)
	const day = ndate.getDay().toString().padStart(2,0)
	return year + "." + month + "." + day
}

// 获取本地缓存
const getStorageSync = (key)=> {
	try {
		const value = uni.getStorageSync(key);
		if (value) {
			return value;
		}else{
			return false;
		}
	} catch (e) {
		console.log(e)
	}
}

// 写入本地缓存
const setStorageSync = (key, data) => {
	try {
		uni.setStorageSync(key, data);
	} catch (e) {
		console.log(e)
	}
}

// 滚动高度
const scrollHeight = (heightArr) => {
	let windowHeight = 0;
	uni.getSystemInfo({
		success: function (res) {
			windowHeight = res.windowHeight;
			for( let i = 0; i < heightArr.length; i++){
				windowHeight -= heightArr[i];
			}
		}
	});

	return windowHeight;
}

export default {
	jump,
	formatDate,
	getStorageSync,
	setStorageSync,
	scrollHeight
}